# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
import csv

from itemadapter import ItemAdapter


class MyspiderPipeline:
    lst = []
    def process_item(self, item, spider):
        self.lst.append(item)
        head = ('author', 'tags', 'text')
        with open('demo.csv', 'w', encoding='utf-8-sig', newline='') as f:
            w = csv.DictWriter(f, fieldnames=head)
            w.writeheader()
            w.writerows(self.lst)
        return item
